﻿using System;
using System.Collections.Generic;
using Evpo.ContactData.Common;
using System.Data.SqlClient;
using System.Data;

namespace Evpo.ContactData.Data
{
    public class HomeTownAdapter : AdapterBase, IEditableDictionaryItemAdapter
    {
        public HomeTownAdapter(Connection connection)
            : base(connection)
        {
            _dictItemAdapter = new HomeTownAdapterInternal(connection);
        }

        #region Fields
        private readonly DictionaryItemAdapter _dictItemAdapter;
        #endregion

        #region Properties
        protected override string PrimaryKeyField
        {
            get { return Fields.ID; }
        }

        protected override string SProcToDelete
        {
            get { return SProcs.DeleteHomeTown; }
        }

        protected override string SProcToLoad
        {
            get { return SProcs.GetHomeTown; }
        }

        protected override string SProcToSave
        {
            get { return SProcs.SaveHomeTown; }
        }

        protected override string SProcToQuery
        {
            get { return SProcs.GetHomeTown; }
        }
        #endregion

        #region Methods

        public string GetDisplayName()
        {
            return _dictItemAdapter.GetDisplayName();
        }

        public DictionaryItem CreateNewItem()
        {
            return new DictionaryItem();
        }

        public List<DictionaryItem> GetItems()
        {
            return _dictItemAdapter.GetDictionaryItems<DictionaryItem>(SProcs.GetHomeTowns);
        }

        public DictionaryItem GetItem(int id)
        {
            return _dictItemAdapter.GetDictionaryItem<DictionaryItem>(id);
        }

        public void Save(DictionaryItem dictItem, bool isNew)
        {
            Save<DictionaryItem>(dictItem, isNew);
        }

        public string GetName(int id)
        {
            return _dictItemAdapter.GetName(id);
        }

        public int GetIDForUnspecified()
        {
            return _dictItemAdapter.GetIDForUnspecified();
        }
        #endregion Methods

        #region Classes
        private class Fields
        {
            internal const string ID = "ID";
            internal const string Name = "Name";
        }

        private class HomeTownAdapterInternal : DictionaryItemAdapter
        {
            public HomeTownAdapterInternal(Connection conn) : base(conn) { }

            protected override string GetItemSProc
            {
                get
                {
                    return SProcs.GetHomeTown;
                }
            }

            protected override string DictionaryName
            {
                get
                {
                    return "HomeTown";
                }
            }
        }
        #endregion Classes
    }
}
